<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="skladiscenje.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>SKLADISCENJE systems</title>
        <LINK href="CSS/style.css" rel="stylesheet" type="text/css" />
        <LINK REL="SHORTCUT ICON" HREF="images/favicon.ico" />
        <script type="text/javascript">
		function zapri(){
			self.close();
		}

		function shraniBlago(id){
			var ime = document.getElementById("ime").value;
			var tip = document.getElementById("tip").value;
			var kolicina = document.getElementById("kolicina").value;
			var enota = document.getElementById("enota").value;
			var sektor = document.getElementById("sektor").value;
			var dovoljenaKolicina = document.getElementById("dovoljenaKolicina").value;
			parent.location = "urejanje.jsp?shrani=true&tipBU=blago&id="+id+"&ime="+ime+"&tip="+tip+"&kolicina="+kolicina+"&enota="+enota+"&sektor="+sektor+"&dovoljenaKolicina="+dovoljenaKolicina;
			self.close();
		}

		function shraniUporabnika(id, skladiscnik){
			var ime = document.getElementById("ime").value;
			var priimek = document.getElementById("priimek").value;
			var uIme = document.getElementById("uIme").value;
			var geslo = document.getElementById("geslo").value;
			var racun = document.getElementById("racun").value;
			var email = document.getElementById("email").value;
			var naslov = document.getElementById("naslov").value;
			if(skladiscnik){
				var sektor = document.getElementById("sektor").value;
				parent.location = "urejanje.jsp?shrani=true&tipBU=skladiscnik&id="+id+"&ime="+ime+"&priimek="+priimek+"&uIme="+uIme+"&geslo="+geslo+"&racun="+racun+"&email="+email+"&naslov="+naslov+"&sektor="+sektor;
			}else{
				parent.location = "urejanje.jsp?shrani=true&tipBU=vodja&id="+id+"&ime="+ime+"&priimek="+priimek+"&uIme="+uIme+"&geslo="+geslo+"&racun="+racun+"&email="+email+"&naslov="+naslov;
			}
			self.close();
		}
		</script>
    </head>

    <body 
    <%if(request.getParameter("tipBU").equals("blago")){ %> 
    onunload="opener.location=('urejanjeBlaga.jsp')">
    <%}else{ %>
    onunload="opener.location=('urejanjeUporabnikov.jsp')">
    <%} %>
		<%
		if(request.getParameter("potrdi") != null){
			String tipBU = request.getParameter("tipBU");
			int id = Integer.parseInt(request.getParameter("id"));
			
			if(tipBU.equals("blago")){
				Blago blago = Evidenca.getBlagoById(id);
				%>
				<table class="urejanje" width="100%" cellspacing="3" cellpadding="2">
					<tr>
						<td colspan="2"><h1>Urejanje blaga!</h1></td>
					</tr>
					<tr>
						<td colspan="2">ps: prikaz tipa in enote je v obdelavi!</td>
					</tr>
					<tr>
						<td class="desna">Ime: </td>
						<td class="leva"><input type="text" name="ime" id="ime" value="<%= blago.getIme() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Tip: </td>
						<td class="leva"><input type="text" name="tip" id="tip" value="<%= blago.getTip() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Količina: </td>
						<td class="leva"><input type="text" name="kolicina" id="kolicina" value="<%= blago.getKolicina() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Enota: </td>
						<td class="leva"><input type="text" name="enota" id="enota" value="<%= blago.getEnota() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Sektor: </td>
						<td class="leva"><input type="text" name="sektor" id="sektor" value="<%= blago.getSektor() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Dovoljena količina: </td>
						<td class="leva"><input type="text" name="dovoljenaKolicina" id="dovoljenaKolicina" value="<%= blago.getDovoljenaKolicina() %>" /></td>
					</tr>
					<tr>
						<td class="desna"><input type="submit" name="preklici" value="Prekliči" onCLick="zapri()" /></td>
						<td class="leva"><input type="submit" name="shrani" value="Shrani spremembe" onClick="shraniBlago(<%= id %>)" /></td>
					</tr>
				</table>
				<%
			}else{
				Uporabnik uporabnik = Evidenca.getUporabnikByID(id);
				%>
				<table class="urejanje" width="100%" cellspacing="3" cellpadding="2">
					<tr>
						<td colspan="2"><h1>Urejanje uporabnika!</h1></td>
					</tr>
					<tr>
						<td class="desna">Ime: </td>
						<td class="leva"><input type="text" name="ime" id="ime" value="<%= uporabnik.getIme() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Priimek: </td>
						<td class="leva"><input type="text" name="priimek" id="priimek" value="<%= uporabnik.getPriimek() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Uporabniško ime: </td>
						<td class="leva"><input type="text" name="uIme" id="uIme" value="<%= uporabnik.getUporabniskoIme() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Geslo: </td>
						<td class="leva"><input type="text" name="geslo" id="geslo" value="<%= uporabnik.getGeslo() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Račun: </td>
						<td class="leva"><input type="text" name="racun" id="racun" value="<%= uporabnik.getRacun() %>" /></td>
					</tr>
					<tr>
						<td class="desna">e-mail: </td>
						<td class="leva"><input type="text" name="email" id="email" value="<%= uporabnik.getEmail() %>" /></td>
					</tr>
					<tr>
						<td class="desna">Naslov: </td>
						<td class="leva"><input type="text" name="naslov" id="naslov" value="<%= uporabnik.getNaslov() %>" /></td>
					</tr>
					<% if(uporabnik.getSektor() != 0){ %>
					<tr>
						<td class="desna">Sektor: </td>
						<td class="leva"><input type="text" name="sektor" id="sektor" value="<%= uporabnik.getSektor() %>" /></td>
					</tr>
					<% } %>
					<tr>
						<td class="desna"><input type="submit" name="preklici" value="Prekliči" onCLick="zapri()" /></td>
						<% if(uporabnik.getSektor() != 0) { %>
						<td class="leva"><input type="submit" name="shrani" value="Shrani spremembe" onClick="shraniUporabnika(<%= id %>, true)" /></td>
						<% }else{ %>
						<td class="leva"><input type="submit" name="shrani" value="Shrani spremembe" onClick="shraniUporabnika(<%= id %>, false)" /></td>
						<% } %>
					</tr>
				</table>
				<%
			}				
		}
		if(request.getParameter("shrani") != null){
			String tipBU = request.getParameter("tipBU");
			if(tipBU.equals("blago")){
				Evidenca.posodobitevBlaga(Integer.parseInt(request.getParameter("id")),
										  request.getParameter("ime"),
										  Integer.parseInt(request.getParameter("tip")),
										  Integer.parseInt(request.getParameter("kolicina")),
										  Integer.parseInt(request.getParameter("enota")),
										  Integer.parseInt(request.getParameter("sektor")),
										  Integer.parseInt(request.getParameter("dovoljenaKolicina")));
			}else if (tipBU.equals("skladiscnik")){
				Evidenca.posodobitevSkladiscnika(Integer.parseInt(request.getParameter("id")),
												 request.getParameter("ime"),
												 request.getParameter("priimek"),
												 request.getParameter("uIme"),
												 request.getParameter("geslo"),
												 request.getParameter("racun"),
												 request.getParameter("email"),
												 request.getParameter("naslov"),
												 Integer.parseInt(request.getParameter("sektor")));
			}else{
				Evidenca.posodobitevVodje(Integer.parseInt(request.getParameter("id")),
										  request.getParameter("ime"),
										  request.getParameter("priimek"),
										  request.getParameter("uIme"),
										  request.getParameter("geslo"),
										  request.getParameter("racun"),
										  request.getParameter("email"),
										  request.getParameter("naslov"));
			}
		}
		%>
	</body>
</html>